package collection;

import java.util.HashMap;

/**
 * 实现一个HashSet
 */
public class Mycollection_HashSet {
    HashMap map;
    private static final Object PRESENT = new Object();
    public Mycollection_HashSet(){
        map = new HashMap();
    }

    public int size(){
        return map.size();
    }

    public void add(Object obj){
        map.put(obj,PRESENT);//vale都是相同的
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (Object key:map.keySet()){
            sb.append(key+",");
        }
        sb.setCharAt(sb.length()-1,']');
        return sb.toString();
    }

    public static void main(String[] args) {
        Mycollection_HashSet s = new Mycollection_HashSet();
        s.add("aa");
        System.out.println(s);
    }
}
